package com.etymgiko.lyricscollectionseam.session;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.jboss.seam.annotations.Name;

import com.etymgiko.lyricscollectionseam.entity.Artist;

/**
 * @author Ivan Holub
 */
@Stateless
@Name("artistManager")
public class ArtistManagerImpl implements ArtistManager {

	@PersistenceContext
	private EntityManager em;

	public Artist findArtist(String name) {
		Query query = em
				.createQuery("select artist from Artist artist where artist.name = ?");
		query.setParameter(1, name);
		Artist retValue = null;
		List<Artist> list = query.getResultList();
		if (list.size() > 0) {
			retValue = list.get(0);
		}

		return retValue;
	}

}
